@extends('Admin.layout.layout')
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>项目信息管理</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <form action="" method="get">
                                {{csrf_field()}}
                                <div class="col-sm-12">
                                    <div class="input-group fl mr10">
                                        <a href="" class="btn btn-sm btn-success "><i class="fa fa-refresh"></i> 刷新</a>
                                    </div>
                                    <div class="input-group fl mr10">
                                        <a class="btn btn-sm btn-primary fl " href="{{url('/foradmin/project/create')}}">新增</a>
                                    </div>
                                    <div class="input-group fr mr10">
                                        <button type="submit" class="btn btn-sm btn-primary fr">查询</button>
                                    </div>
                                    <div class="input-group fr mr10">
                                        <input type="text" title="" placeholder="标题/创建人" class="input-sm form-control fl" name="keyword" value="{{array_get($search_params,'keyword')}}">
                                    </div>
                                </div>
                            </form>
                        </div>
                        <table class="table table-striped table-bordered table-hover dataTable" id="editable">
                            <thead>
                            <tr>
                                <th width="5%">序号</th>
                                <th width="35%">标题</th>
                                <th width="10%" class="center">项目类型</th>
                                <th width="15%" class="center">创建时间</th>
                                <th width="10%" class="center">创建人</th>
                                <th width="10%" class="center">审核状态</th>
                                <th width="15%" class="center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if(!empty($list))
                                @foreach($list as $k =>$v)
                                    <tr class="gradeX">
                                        <td>{{$v['project_id']}}</td>
                                        <td>{{$v['title']}}<a href="{{url('/find/message/detail')}}/{{$v['project_id']}}" target="view_window" class="btn btn-info btn-xs fr">预览</a></td>
                                        <td class="center">{{$v['type_name']}}</td>
                                        <td class="center">{{$v['created_at']}}</td>
                                        <td class="center">{{isset($v['admin_user']['name'])?$v['admin_user']['name']:'admin'}}</td>
                                        <td class="center">{{$v['check_status_name']}}</td>
                                        <td class="center">
                                            <div class="btn-group">
                                                <button data-toggle="dropdown" class="btn btn-success btn-sm dropdown-toggle">操作 <span class="caret"></span>
                                                </button>
                                                <ul class="dropdown-menu">
                                                    @if($v['check_status']!='uncheck')
                                                    <li data-id="{{array_get($v,'project_id')}}" data-type="uncheck">
                                                        <a>设为未审核</a>
                                                    </li>
                                                    @endif
                                                    @if($v['check_status']!='pass')
                                                    <li data-id="{{array_get($v,'project_id')}}" data-type="pass">
                                                        <a>设为已审核</a>
                                                    </li>
                                                    @endif
                                                    @if($v['check_status']!='failed')
                                                    <li data-id="{{array_get($v,'project_id')}}" data-type="failed">
                                                        <a>设为审核失败</a>
                                                    </li>
                                                    @endif
                                                </ul>
                                            </div>
                                            <button class="btn btn-sm btn-primary check_order" data-id="{{$v['project_id']}}">编辑</button>
                                            <button class="btn btn-sm btn-danger"
                                                    data-url="{{URL::to('foradmin/project/'.$v['project_id'])}}"
                                                    data-toggle="modal"
                                                    data-target="#delete-modal"
                                            >删除</button>
                                        </td>
                                    </tr>
                                @endforeach
                            @else
                                <tr class="no-records-found center"><td colspan="9">没有找到匹配的记录</td></tr>
                            @endif
                            </tbody>
                        </table>
                        <div class="row">
                            @include('Admin.common.paginate')
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script src="{{asset('js/plugins/layer/laydate/laydate.js')}}"></script>
    <script src="{{asset('js/plugins/layer/layer.min.js')}}"></script>

    <script>
        //查看
        $('.check_order').click(function(){
            var id=$(this).attr('data-id');
//            var url = 'foradmin/project/'+id;
            var url = '/foradmin/project/' + $(this).data('id')+'/edit';//前端正式
            var title = '项目详情';
            open_page(url, title);//打开新页面
        });

        //展示
        function audit(id,audit){
            var msg = '';
            if (audit==2){
                msg = '取消展示';
            }else{
                msg = '展示';
            }
            layer.confirm('确认修改状态为【'+msg+'】状态？',{
                btn: ['确认', '取消'] //可以无限个按钮
            },function(index) {
                $.ajax({
                    url: '{{Request::url()}}/audit/'+id,
                    type: 'put',
                    dataType: 'json',
                    data: {'audit' : audit},
                    success: function (data) {
                        if (0 == data.code) {
                            //                        layer.alert(data.message?data.message:data.data, {
                            //                            icon: 1
                            //                        }, function () {
                            if(audit==1){
                                var str="<a href=\"javascript:void 0;\" onclick=\"audit("+id+",2)\">展示</a>";
                                $("#audit_text_"+id).html(str);
                            }else{
                                var str="<a href=\"javascript:void 0;\" onclick=\"audit("+id+",1)\">取消展示</a>";
                                $("#audit_text_"+id).html(str);
                            }
                            //                            location.reload();
                            //                        });
                        } else {
                            layer.alert(data.message, {
                                icon: 2
                            });
                        }
                    }
                });
                layer.close(index);
            })

        }
        //推荐
        function recommend(id,recommend){
            console.log(recommend);
            var msg = '';
            if (recommend==2){
                msg = '取消推荐';
            }else{
                msg = '推荐';
            }
            layer.confirm('确认修改状态为【'+msg+'】状态？',{
                btn: ['确认', '取消'] //可以无限个按钮
            },function(index) {
                $.ajax({
                    url: '{{Request::url()}}/recommend/'+id,
                    type: 'put',
                    dataType: 'json',
                    data: {'recommend' : recommend},
                    success: function (data) {
                        if (0 == data.code) {

                            if(recommend==1){
                                var str="<a href=\"javascript:void 0;\" onclick=\"recommend("+id+",2)\">推荐</a>";
                                $("#recommend_text_"+id).html(str);
                            }else{
                                var str="<a href=\"javascript:void 0;\" onclick=\"recommend("+id+",1)\">取消推荐</a>";
                                $("#recommend_text_"+id).html(str);
                            }
                        } else {
                            layer.alert(data.message, {
                                icon: 2
                            });
                        }
                    }
                });
                layer.close(index);
            })

        }
        $('.dropdown-menu li').click(function(){
            var id = $(this).attr('data-id');
            var type = $(this).attr('data-type');
            if(type=='uncheck'){
                msg = '未审核';
            }else if (type=='pass'){
                msg = '已审核';
            }else {
                msg = '审核失败';
            }
            layer.confirm('确认处理此项目信息为【'+msg+'】状态？',{
                btn: ['确认', '取消'] //可以无限个按钮
            },function(index) {
                $.ajax({
                    url: '{{Request::url()}}/setCheckStatus/'+ id,
                    type: 'POST',
                    dataType: 'json',
                    data: {'id': id, 'check_status': type},
                    success: function (data) {
                        if (0 == data.code) {
                            layer.alert('设置成功！', {
                                icon: 1
                            }, function () {
                                location.reload();
                            });
                        } else {
                            layer.alert(data.message, {
                                icon: 2
                            });
                        }
                    }
                });
                layer.close(index);
            })
        })
    </script>
@endsection

@section("after.js")
    @include('Admin.components.modal.delete',['title'=>'操作提示','content'=>'你确定要删除这篇文章吗?'])
@endsection